<template>
  <a-card :bordered='false'>
    <search :config='searchConfig' @search='search' @getHeight='getHeight' />
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-94'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config="tableToolbar"
       :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
          <a-button type="primary" @click="downExportXls('sfaWork_service')">导出</a-button>
          </div>
        </template>


        <template  #action='{ row,rowIndex }'>
          <a v-has="'getGoodsAdress:update'" @click='handleEdit(row)'>编辑</a>
          <a-divider type='vertical' />
          <a href='javascript:' @click='handleBusiness("收货地址",row)'>日志</a>

        </template>
        <template #detail ='{ row,rowIndex }'>
          <a @click="handleDetail(row)">{{ row.createBy }}</a>
        </template>
        <template #update='{ row }'>
          <a-switch :checked='row.status' size='small' @change='handleStatus(row,$event)' />
        </template>
        <template #update='{ row }'>
          <a-switch :checked='row.status' size='small' @change='handleStatus(row,$event)' />
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <getGoods ref="modalForm" @ok="modalFormOk"></getGoods>
    <business-log ref='businessLog'></business-log>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import {PageListMixin} from '@/mixins/PageListMixin'
  import {getAction} from '@/api/manage'
  import ARow from 'ant-design-vue/es/grid/Row'
  import ARangePicker from 'ant-design-vue/es/date-picker/RangePicker'

  export default {
    name: "SignConfigList",
    mixins: [PageListMixin],
    components: {
      ARangePicker,
      ARow
    },
    data() {
      return {
        description: '加班申请明细报表页面',
        // 表头
        searchConfig: [
          {
            type: 'input',
            name: 'createName',
            placeholder: '申请人'
          },
          {
            type: 'date',
            name: 'createTime',
            placeholder: '申请日期'
          },
          // {
          //   type: 'j-select',
          //   name: 'bpmStatus',
          //   dictCode: 'bpm_status',
          //   placeholder: '审批状态'
          // },
          {
            type: 'a-select',
            name: 'bpmStatus',
            placeholder: '审批状态',
            option: [
              {
                name: '待审批',
                value: '1'
              },
              {
                name: '审批通过',
                value: '2'
              },
              {
                name: '审批驳回',
                value: '3'
              }]
          },
          {
            type: 'date-range', //范围选择
            range: ['startTime', 'endTime'],
            name: 'range',
            format: 'YYYY-MM-DD',
            placeholder: ['开始时间', '结束时间']
          }
          // {
          //   type: 'j-select',
          //   name: 'orgName',
          //   dictCode:'orgName',
          //   placeholder: '请选择所属组织'
          // }
        ],
        columns: [
          {
            width:60,
            type:'checkbox',
          },
          {
            title: '申请人账号',
            minWidth:80,
            field: 'createBy',
            // slots: { default: 'detail' }
          },
          {
            title: '申请人姓名',
            minWidth:80,
            field: 'createName',
          },
          {
            title: '申请人职位',
            minWidth:100,
            field: 'posName'
          },
          {
            title: '所属组织',
            minWidth:80,
            field: 'orgName'
          },
          {
            title: '申请日期',
            minWidth:80,
            field: 'createTime'
          },
          {
            title: '开始时间',
            minWidth:80,
            field: 'startTime'
          },
          {
            title: '结束时间',
            minWidth:80,
            field: 'endTime'
          },
          {
            title: '加班时长(小时)',
            minWidth:80,
            field: 'workTime'
          },
          {
            title: '加班事由',
            minWidth:80,
            field: 'workReason',
          },
          {
            title: '审批状态',
            minWidth:80,
            field: 'bpmStatusStr',
          },
        ],
        isorter: {
          permflag: 'sfa_work_list'
        },
        url: {
          list: window._CONFIG['domianSfaURL'] + "/work/findPageList",
          delete: window._CONFIG['domianSfaURL'] + "/signConfig/deleteById",
          detail: window._CONFIG['domianURL'] + '/cnUserController/getUserByIdOrCode',
          deleteBatch: window._CONFIG['domianSfaURL'] + "/signConfig/deleteBatch",
          startOrStopUrl: window._CONFIG['domianSfaURL'] + "/signConfig/status/startOrStop"
        }
      }
    },

    methods: {
      startorstop: function (status) {

        if (!this.url.startOrStopUrl) {
          this.$message.error("请设置url启用停用!")
          return;
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        }
        let param = {...this.queryParam}
        param['status'] = status
        if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
          param['selections'] = this.selectedRowKeys.join(",")
        }else {
          param['selections'] = this.selectedRowKeys[0]
        }
        // if (this.selectedRowKeys.length != 1) {
        //   this.$message.warning('请选择一条记录！');
        //   return;
        // } else {
        // var id = this.selectedRowKeys;
        var that = this;
        that.loading = true;
        getAction(this.url.startOrStopUrl, param ).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
          that.loading = false;
        });
      }
    }

  }
</script>

<style scoped>
  @import '~@assets/less/common.less';
</style>